package com.lgCore.util;



import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * 文件数值获取
 */
public class PropertyValues {

    public static Properties properties;
//    static {
//        loadPropertyValue();
//    }
    public PropertyValues(String propertiesName){
        loadPropertyValue(propertiesName);
    }
    public static void loadPropertyValue(String propertiesName){
        InputStream inputStream=null;
        inputStream= PropertyValues.class.getClassLoader().getResourceAsStream(propertiesName);

        //若配置文件中有中文的话需要做以下配置
        //.propertis文件中的中文是字节流,中文读取需要转换成字符流才能正常读取
        //==start
        BufferedReader bufferedReader=new BufferedReader(new
                InputStreamReader(inputStream));
        //=====end=======

        properties=new Properties();
        try {
            properties.load(inputStream);
        }catch (Exception e){
            System.out.println("get value failed!");
        }finally {
            try {
                inputStream.close();
            }catch (Exception e){
                System.out.println("IO close exception!");
            }

        }

    }

    public String getPropertyValue(String key){
        return  properties.getProperty(key);
    }

}
